package role

import (
	"context"
	"trusteva/app/rbac/model"

	"trusteva/app/rbac/internal/svc"
	"trusteva/app/rbac/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleUpdateLogic {
	return &RoleUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleUpdateLogic) RoleUpdate(req *types.RoleUpdateRo) (resp *types.BaseRsp, err error) {
	err = l.svcCtx.DB.WithContext(l.ctx).Where("Id=?", req.RoleId).
		Select("Name", "IsRoot", "Status", "Memo").
		Updates(&model.RoleConfig{
			Name:   req.Name,
			IsRoot: req.IsRoot,
			Status: model.LimitStatus(req.Status),
			Memo:   req.Memo,
		}).Error
	return
}
